<!DOCTYPE html>
<html>
<head>
    

    

    



    <meta charset="utf-8">
    
    
    
    <title>django官方文档快捷链接 | Cucy的博客</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="django">
    <meta name="description" content="官方快捷链接 django http Django如何处理一个http请求404，403，500错误Including other URLconfs语法Reverse resolution of URLs 反向解析URL namespaces命名空间A simple viewReturning errors返回错误Customizing error views自定义错误页面View decorat">
<meta name="keywords" content="django">
<meta property="og:type" content="article">
<meta property="og:title" content="django官方文档快捷链接">
<meta property="og:url" content="http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/index.html">
<meta property="og:site_name" content="Cucy的博客">
<meta property="og:description" content="官方快捷链接 django http Django如何处理一个http请求404，403，500错误Including other URLconfs语法Reverse resolution of URLs 反向解析URL namespaces命名空间A simple viewReturning errors返回错误Customizing error views自定义错误页面View decorat">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2017-09-13T09:19:30.547Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="django官方文档快捷链接">
<meta name="twitter:description" content="官方快捷链接 django http Django如何处理一个http请求404，403，500错误Including other URLconfs语法Reverse resolution of URLs 反向解析URL namespaces命名空间A simple viewReturning errors返回错误Customizing error views自定义错误页面View decorat">
    
        <link rel="alternate" type="application/atom+xml" title="Cucy的博客" href="/atom.xml">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="/css/style.css?v=1.6.13">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.png">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">cucy</h5>
          <a href="mailto:292016176@qq.com" title="292016176@qq.com" class="mail">292016176@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/cucy" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">django官方文档快捷链接</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">django官方文档快捷链接</h1>
        <h5 class="subtitle">
            
                <time datetime="2017-09-13T09:18:51.000Z" itemprop="datePublished" class="page-time">
  2017-09-13
</time>


            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#django-http"><span class="post-toc-number">1.</span> <span class="post-toc-text">django http</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Django如何处理一个http请求"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">Django如何处理一个http请求</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#404，403，500错误"><span class="post-toc-number">1.2.</span> <span class="post-toc-text">404，403，500错误</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Including-other-URLconfs语法"><span class="post-toc-number">1.3.</span> <span class="post-toc-text">Including other URLconfs语法</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Reverse-resolution-of-URLs-反向解析"><span class="post-toc-number">1.4.</span> <span class="post-toc-text">Reverse resolution of URLs 反向解析</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#URL-namespaces命名空间"><span class="post-toc-number">1.5.</span> <span class="post-toc-text">URL namespaces命名空间</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#A-simple-view"><span class="post-toc-number">1.6.</span> <span class="post-toc-text">A simple view</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Returning-errors返回错误"><span class="post-toc-number">1.7.</span> <span class="post-toc-text">Returning errors返回错误</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Customizing-error-views自定义错误页面"><span class="post-toc-number">1.8.</span> <span class="post-toc-text">Customizing error views自定义错误页面</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#View-decorators-views装饰器"><span class="post-toc-number">1.9.</span> <span class="post-toc-text">View decorators views装饰器</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#File-Uploads-文件上传"><span class="post-toc-number">1.10.</span> <span class="post-toc-text">File Uploads 文件上传 </span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Django-shortcut-functions-django内置快简函数"><span class="post-toc-number">1.11.</span> <span class="post-toc-text">Django shortcut functions django内置快简函数</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Middleware-中间件"><span class="post-toc-number">1.12.</span> <span class="post-toc-text">Middleware 中间件</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#How-to-use-sessions"><span class="post-toc-number">1.13.</span> <span class="post-toc-text">How to use sessions</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Working-with-forms"><span class="post-toc-number">1.14.</span> <span class="post-toc-text">Working with forms</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Rendering-fields-manually"><span class="post-toc-number">1.15.</span> <span class="post-toc-text">Rendering fields manually</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Formsets"><span class="post-toc-number">1.16.</span> <span class="post-toc-text">Formsets</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Creating-forms-from-models"><span class="post-toc-number">1.17.</span> <span class="post-toc-text">Creating forms from models</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Overriding-the-default-fields-重写form字段-自定义、错误信息、样式"><span class="post-toc-number">1.18.</span> <span class="post-toc-text">Overriding the default fields 重写form字段 自定义、错误信息、样式 </span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Changing-the-queryset-修改modelform中的queryset"><span class="post-toc-number">1.19.</span> <span class="post-toc-text">Changing the queryset 修改modelform中的queryset</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Changing-the-form-modelform-中的clean"><span class="post-toc-number">1.20.</span> <span class="post-toc-text">Changing the form modelform 中的clean</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Saving-objects-in-the-formset"><span class="post-toc-number">1.21.</span> <span class="post-toc-text">Saving objects in the formset</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Using-a-model-formset-in-a-view"><span class="post-toc-number">1.22.</span> <span class="post-toc-text">Using a model formset in a view</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Form-Assets-the-Media-class"><span class="post-toc-number">1.23.</span> <span class="post-toc-text">Form Assets (the Media class)</span></a></li></ol></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#Templates¶"><span class="post-toc-number">2.</span> <span class="post-toc-text">Templates¶</span></a></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#Class-based-views¶"><span class="post-toc-number">3.</span> <span class="post-toc-text">Class-based views¶</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Using-class-based-views¶"><span class="post-toc-number">3.1.</span> <span class="post-toc-text">Using class-based views¶</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Using-mixins"><span class="post-toc-number">3.2.</span> <span class="post-toc-text">Using mixins</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Handling-forms-with-class-based-views"><span class="post-toc-number">3.3.</span> <span class="post-toc-text">Handling forms with class-based views</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Decorating-the-class-cbv装饰器"><span class="post-toc-number">3.3.1.</span> <span class="post-toc-text">Decorating the class cbv装饰器</span></a></li></ol></li></ol></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#Built-in-class-based-generic-views-内置通用CBV"><span class="post-toc-number">4.</span> <span class="post-toc-text">Built-in class-based generic views 内置通用CBV</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Generic-views-of-objects"><span class="post-toc-number">4.1.</span> <span class="post-toc-text">Generic views of objects</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Adding-extra-context"><span class="post-toc-number">4.1.1.</span> <span class="post-toc-text">Adding extra context</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Viewing-subsets-of-objects-设定queryset"><span class="post-toc-number">4.1.2.</span> <span class="post-toc-text">Viewing subsets of objects 设定queryset</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Dynamic-filtering-动态过滤"><span class="post-toc-number">4.1.3.</span> <span class="post-toc-text">Dynamic filtering 动态过滤</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Performing-extra-work-动态更新一些信息"><span class="post-toc-number">4.1.4.</span> <span class="post-toc-text">Performing extra work 动态更新一些信息</span></a></li></ol></li></ol></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#Form-handling-with-class-based-views"><span class="post-toc-number">5.</span> <span class="post-toc-text">Form handling with class-based views</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Basic-forms"><span class="post-toc-number">5.1.</span> <span class="post-toc-text">Basic forms</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Model-forms-views-form-formview"><span class="post-toc-number">5.2.</span> <span class="post-toc-text">Model forms views + form = formview </span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Models-and-request-user-额外添加数据"><span class="post-toc-number">5.3.</span> <span class="post-toc-text">Models and request.user  额外添加数据</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#AJAX-example"><span class="post-toc-number">5.4.</span> <span class="post-toc-text">AJAX example</span></a></li></ol></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#Using-mixins-with-class-based-views"><span class="post-toc-number">6.</span> <span class="post-toc-text">Using mixins with class-based views</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Using-SingleObjectMixin-with-View"><span class="post-toc-number">6.0.1.</span> <span class="post-toc-text">Using SingleObjectMixin with View</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Using-SingleObjectMixin-with-ListView"><span class="post-toc-number">6.0.2.</span> <span class="post-toc-text"> Using SingleObjectMixin with ListView</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Using-FormMixin-with-DetailView"><span class="post-toc-number">6.0.3.</span> <span class="post-toc-text">Using FormMixin with DetailView</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#More-than-just-HTML"><span class="post-toc-number">6.1.</span> <span class="post-toc-text">More than just HTML</span></a></li></ol></li></ol>
        </nav>
    </aside>
    
<article id="post-47-django官方文档快捷链接"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">django官方文档快捷链接</h1>
        <div class="post-meta">
            <time class="post-time" title="2017-09-13 17:18:51" datetime="2017-09-13T09:18:51.000Z"  itemprop="datePublished">2017-09-13</time>

            


            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <p>官方快捷链接</p>
<h1 id="django-http"><a href="#django-http" class="headerlink" title="django http"></a>django http</h1><hr>
<h2 id="Django如何处理一个http请求"><a href="#Django如何处理一个http请求" class="headerlink" title="Django如何处理一个http请求"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/urls/#how-django-processes-a-request" target="_blank" rel="external">Django如何处理一个http请求</a></h2><h2 id="404，403，500错误"><a href="#404，403，500错误" class="headerlink" title="404，403，500错误"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/urls/#error-handling" target="_blank" rel="external">404，403，500错误</a></h2><h2 id="Including-other-URLconfs语法"><a href="#Including-other-URLconfs语法" class="headerlink" title="Including other URLconfs语法"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/urls/#including-other-urlconfs" target="_blank" rel="external">Including other URLconfs语法</a></h2><h2 id="Reverse-resolution-of-URLs-反向解析"><a href="#Reverse-resolution-of-URLs-反向解析" class="headerlink" title="Reverse resolution of URLs 反向解析"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/urls/#reverse-resolution-of-urls" target="_blank" rel="external">Reverse resolution of URLs 反向解析</a></h2><h2 id="URL-namespaces命名空间"><a href="#URL-namespaces命名空间" class="headerlink" title="URL namespaces命名空间"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/urls/#url-namespaces" target="_blank" rel="external">URL namespaces命名空间</a></h2><h2 id="A-simple-view"><a href="#A-simple-view" class="headerlink" title="A simple view"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/views/#a-simple-view" target="_blank" rel="external">A simple view</a></h2><h2 id="Returning-errors返回错误"><a href="#Returning-errors返回错误" class="headerlink" title="Returning errors返回错误"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/views/#returning-errors" target="_blank" rel="external">Returning errors返回错误</a></h2><h2 id="Customizing-error-views自定义错误页面"><a href="#Customizing-error-views自定义错误页面" class="headerlink" title="Customizing error views自定义错误页面"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/views/#customizing-error-views" target="_blank" rel="external">Customizing error views自定义错误页面</a></h2><h2 id="View-decorators-views装饰器"><a href="#View-decorators-views装饰器" class="headerlink" title="View decorators views装饰器"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/decorators/#module-django.views.decorators.http" target="_blank" rel="external">View decorators views装饰器</a></h2><h2 id="File-Uploads-文件上传"><a href="#File-Uploads-文件上传" class="headerlink" title="File Uploads 文件上传 "></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/file-uploads/#file-uploads" target="_blank" rel="external">File Uploads 文件上传</a> </h2><h2 id="Django-shortcut-functions-django内置快简函数"><a href="#Django-shortcut-functions-django内置快简函数" class="headerlink" title="Django shortcut functions django内置快简函数"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/shortcuts/#module-django.shortcuts" target="_blank" rel="external">Django shortcut functions django内置快简函数</a></h2><h2 id="Middleware-中间件"><a href="#Middleware-中间件" class="headerlink" title="Middleware 中间件"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/middleware/#middleware" target="_blank" rel="external">Middleware 中间件</a></h2><h2 id="How-to-use-sessions"><a href="#How-to-use-sessions" class="headerlink" title="How to use sessions"></a><a href="https://docs.djangoproject.com/en/1.11/topics/http/sessions/#module-django.contrib.sessions" target="_blank" rel="external">How to use sessions</a></h2><h2 id="Working-with-forms"><a href="#Working-with-forms" class="headerlink" title="Working with forms"></a><a href="https://docs.djangoproject.com/en/1.11/topics/forms/#working-with-forms" target="_blank" rel="external">Working with forms</a></h2><h2 id="Rendering-fields-manually"><a href="#Rendering-fields-manually" class="headerlink" title="Rendering fields manually"></a><a href="https://docs.djangoproject.com/en/1.11/topics/forms/#rendering-fields-manually" target="_blank" rel="external">Rendering fields manually</a></h2><h2 id="Formsets"><a href="#Formsets" class="headerlink" title="Formsets"></a><a href="https://docs.djangoproject.com/en/1.11/topics/forms/formsets/#module-django.forms.formsets" target="_blank" rel="external">Formsets</a></h2><h2 id="Creating-forms-from-models"><a href="#Creating-forms-from-models" class="headerlink" title="Creating forms from models"></a><a href="https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/#module-django.forms.models" target="_blank" rel="external">Creating forms from models</a></h2><h2 id="Overriding-the-default-fields-重写form字段-自定义、错误信息、样式"><a href="#Overriding-the-default-fields-重写form字段-自定义、错误信息、样式" class="headerlink" title="Overriding the default fields 重写form字段 自定义、错误信息、样式 "></a><a href="https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/#overriding-the-default-fields" target="_blank" rel="external">Overriding the default fields 重写form字段 自定义、错误信息、样式</a> </h2><h2 id="Changing-the-queryset-修改modelform中的queryset"><a href="#Changing-the-queryset-修改modelform中的queryset" class="headerlink" title="Changing the queryset 修改modelform中的queryset"></a><a href="https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/#changing-the-queryset" target="_blank" rel="external">Changing the queryset 修改modelform中的queryset</a></h2><h2 id="Changing-the-form-modelform-中的clean"><a href="#Changing-the-form-modelform-中的clean" class="headerlink" title="Changing the form modelform 中的clean"></a><a href="https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/#changing-the-form" target="_blank" rel="external">Changing the form modelform 中的clean</a></h2><h2 id="Saving-objects-in-the-formset"><a href="#Saving-objects-in-the-formset" class="headerlink" title="Saving objects in the formset"></a><a href="https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/#saving-objects-in-the-formset" target="_blank" rel="external">Saving objects in the formset</a></h2><h2 id="Using-a-model-formset-in-a-view"><a href="#Using-a-model-formset-in-a-view" class="headerlink" title="Using a model formset in a view"></a><a href="https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/#using-a-model-formset-in-a-view" target="_blank" rel="external">Using a model formset in a view</a></h2><h2 id="Form-Assets-the-Media-class"><a href="#Form-Assets-the-Media-class" class="headerlink" title="Form Assets (the Media class)"></a><a href="https://docs.djangoproject.com/en/1.11/topics/forms/media/#form-assets-the-media-class" target="_blank" rel="external">Form Assets (the <code>Media</code> class)</a></h2><h1 id="Templates¶"><a href="#Templates¶" class="headerlink" title="Templates¶"></a>Templates<a href="https://docs.djangoproject.com/en/1.11/topics/templates/#module-django.template" target="_blank" rel="external">¶</a></h1><hr>
<h1 id="Class-based-views¶"><a href="#Class-based-views¶" class="headerlink" title="Class-based views¶"></a>Class-based views<a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/#class-based-views" target="_blank" rel="external">¶</a></h1><ul>
<li><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/intro/" target="_blank" rel="external">Introduction to class-based views</a></li>
<li><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-display/" target="_blank" rel="external">Built-in class-based generic views</a></li>
<li><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-editing/" target="_blank" rel="external">Form handling with class-based views</a></li>
<li><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/mixins/" target="_blank" rel="external">Using mixins with class-based views</a></li>
</ul>
<hr>
<h2 id="Using-class-based-views¶"><a href="#Using-class-based-views¶" class="headerlink" title="Using class-based views¶"></a>Using class-based views<a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/intro/#using-class-based-views" target="_blank" rel="external">¶</a></h2><h2 id="Using-mixins"><a href="#Using-mixins" class="headerlink" title="Using mixins"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/intro/#using-mixins" target="_blank" rel="external">Using mixins</a></h2><h2 id="Handling-forms-with-class-based-views"><a href="#Handling-forms-with-class-based-views" class="headerlink" title="Handling forms with class-based views"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/intro/#handling-forms-with-class-based-views" target="_blank" rel="external">Handling forms with class-based views</a></h2><h3 id="Decorating-the-class-cbv装饰器"><a href="#Decorating-the-class-cbv装饰器" class="headerlink" title="Decorating the class cbv装饰器"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/intro/#decorating-the-class" target="_blank" rel="external">Decorating the class cbv装饰器</a></h3><h1 id="Built-in-class-based-generic-views-内置通用CBV"><a href="#Built-in-class-based-generic-views-内置通用CBV" class="headerlink" title="Built-in class-based generic views 内置通用CBV"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-display/#built-in-class-based-generic-views" target="_blank" rel="external">Built-in class-based generic views 内置通用CBV</a></h1><h2 id="Generic-views-of-objects"><a href="#Generic-views-of-objects" class="headerlink" title="Generic views of objects"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-display/#generic-views-of-objects" target="_blank" rel="external">Generic views of objects</a></h2><h3 id="Adding-extra-context"><a href="#Adding-extra-context" class="headerlink" title="Adding extra context"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-display/#adding-extra-context" target="_blank" rel="external">Adding extra context</a></h3><h3 id="Viewing-subsets-of-objects-设定queryset"><a href="#Viewing-subsets-of-objects-设定queryset" class="headerlink" title="Viewing subsets of objects 设定queryset"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-display/#viewing-subsets-of-objects" target="_blank" rel="external">Viewing subsets of objects 设定queryset</a></h3><h3 id="Dynamic-filtering-动态过滤"><a href="#Dynamic-filtering-动态过滤" class="headerlink" title="Dynamic filtering 动态过滤"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-display/#dynamic-filtering" target="_blank" rel="external">Dynamic filtering 动态过滤</a></h3><h3 id="Performing-extra-work-动态更新一些信息"><a href="#Performing-extra-work-动态更新一些信息" class="headerlink" title="Performing extra work 动态更新一些信息"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-display/#performing-extra-work" target="_blank" rel="external">Performing extra work 动态更新一些信息</a></h3><h1 id="Form-handling-with-class-based-views"><a href="#Form-handling-with-class-based-views" class="headerlink" title="Form handling with class-based views"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-editing/#form-handling-with-class-based-views" target="_blank" rel="external">Form handling with class-based views</a></h1><h2 id="Basic-forms"><a href="#Basic-forms" class="headerlink" title="Basic forms"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-editing/#basic-forms" target="_blank" rel="external">Basic forms</a></h2><p>Notes:</p>
<ul>
<li>FormView inherits <a href="https://docs.djangoproject.com/en/1.11/ref/class-based-views/mixins-simple/#django.views.generic.base.TemplateResponseMixin" target="_blank" rel="external"><code>TemplateResponseMixin</code></a> so <a href="https://docs.djangoproject.com/en/1.11/ref/class-based-views/mixins-simple/#django.views.generic.base.TemplateResponseMixin.template_name" target="_blank" rel="external"><code>template_name</code></a> can be used here.</li>
<li>The default implementation for <a href="https://docs.djangoproject.com/en/1.11/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.form_valid" target="_blank" rel="external"><code>form_valid()</code></a> simply redirects to the <a href="https://docs.djangoproject.com/en/1.11/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.success_url" target="_blank" rel="external"><code>success_url</code></a>.</li>
</ul>
<h2 id="Model-forms-views-form-formview"><a href="#Model-forms-views-form-formview" class="headerlink" title="Model forms views + form = formview "></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-editing/#model-forms" target="_blank" rel="external">Model forms <code>views</code> + <code>form</code> = formview </a></h2><p>You don’t even need to provide a <code>success_url</code> for <a href="https://docs.djangoproject.com/en/1.11/ref/class-based-views/generic-editing/#django.views.generic.edit.CreateView" target="_blank" rel="external"><code>CreateView</code></a> or <a href="https://docs.djangoproject.com/en/1.11/ref/class-based-views/generic-editing/#django.views.generic.edit.UpdateView" target="_blank" rel="external"><code>UpdateView</code></a> - they will use <a href="https://docs.djangoproject.com/en/1.11/ref/models/instances/#django.db.models.Model.get_absolute_url" target="_blank" rel="external"><code>get_absolute_url()</code></a> on the model object if available.</p>
<h2 id="Models-and-request-user-额外添加数据"><a href="#Models-and-request-user-额外添加数据" class="headerlink" title="Models and request.user  额外添加数据"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-editing/#models-and-request-user" target="_blank" rel="external">Models and <code>request.user</code>  额外添加数据</a></h2><h2 id="AJAX-example"><a href="#AJAX-example" class="headerlink" title="AJAX example"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-editing/#ajax-example" target="_blank" rel="external">AJAX example</a></h2><h1 id="Using-mixins-with-class-based-views"><a href="#Using-mixins-with-class-based-views" class="headerlink" title="Using mixins with class-based views"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/mixins/#using-mixins-with-class-based-views" target="_blank" rel="external">Using mixins with class-based views</a></h1><p>For this reason, Django also provides a number of mixins that provide more discrete functionality. Template rendering, for instance, is encapsulated in the <a href="https://docs.djangoproject.com/en/1.11/ref/class-based-views/mixins-simple/#django.views.generic.base.TemplateResponseMixin" target="_blank" rel="external"><code>TemplateResponseMixin</code></a>. The Django reference documentation contains <a href="https://docs.djangoproject.com/en/1.11/ref/class-based-views/mixins/" target="_blank" rel="external">full documentation of all the mixins</a>.</p>
<h3 id="Using-SingleObjectMixin-with-View"><a href="#Using-SingleObjectMixin-with-View" class="headerlink" title="Using SingleObjectMixin with View"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/mixins/#using-singleobjectmixin-with-view" target="_blank" rel="external">Using <code>SingleObjectMixin</code> with View</a></h3><h3 id="Using-SingleObjectMixin-with-ListView"><a href="#Using-SingleObjectMixin-with-ListView" class="headerlink" title=" Using SingleObjectMixin with ListView"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/mixins/#using-singleobjectmixin-with-listview" target="_blank" rel="external"> Using <code>SingleObjectMixin</code> with <code>ListView</code></a></h3><h3 id="Using-FormMixin-with-DetailView"><a href="#Using-FormMixin-with-DetailView" class="headerlink" title="Using FormMixin with DetailView"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/mixins/#using-formmixin-with-detailview" target="_blank" rel="external">Using <code>FormMixin</code> with <code>DetailView</code></a></h3><h2 id="More-than-just-HTML"><a href="#More-than-just-HTML" class="headerlink" title="More than just HTML"></a><a href="https://docs.djangoproject.com/en/1.11/topics/class-based-views/mixins/#more-than-just-html" target="_blank" rel="external">More than just HTML</a></h2>
        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2017-09-13T09:19:30.547Z" itemprop="dateUpdated">2017-09-13 17:19:30</time>
</span><br>


        
        <a href="/2017/09/13/47-django官方文档快捷链接/" target="_blank" rel="external">http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/</a>
        
    </div>
    <footer>
        <a href="http://zhourudong.cn">
            <img src="/img/avatar.png" alt="cucy">
            cucy
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/django/">django</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/&title=《django官方文档快捷链接》 — Cucy的博客&pic=http://zhourudong.cn/img/avatar.png" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/&title=《django官方文档快捷链接》 — Cucy的博客&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《django官方文档快捷链接》 — Cucy的博客&url=http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/&via=http://zhourudong.cn" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2017/09/13/48-django架构/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">django架构</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2017/09/08/46-django-用户模型翻译/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">django 用户模型翻译</h4>
      </a>
    </div>
  
</nav>



    














</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        谢谢大爷~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="/img/wechat.jpg" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check"
                data-wechat="/img/wechat.jpg" data-alipay="/img/alipay.jpg">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechat">微信</span>
                <span class="reward-toggle-label"></span>
                <span class="reward-toggle-item alipay">支付宝</span>
            </div>
        </label>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>cucy &copy; 2016 - 2017</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/&title=《django官方文档快捷链接》 — Cucy的博客&pic=http://zhourudong.cn/img/avatar.png" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/&title=《django官方文档快捷链接》 — Cucy的博客&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《django官方文档快捷链接》 — Cucy的博客&url=http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/&via=http://zhourudong.cn" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="//api.qrserver.com/v1/create-qr-code/?data=http://zhourudong.cn/2017/09/13/47-django官方文档快捷链接/" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="/js/main.min.js?v=1.6.13"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="/js/search.min.js?v=1.6.13" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
